package com.wangbl.infomanager;

import java.io.File;

import cn.jpush.android.api.JPushInterface;

import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiscCache;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.utils.StorageUtils;
import com.tangye.android.http.HttpManager;

import android.app.Application;

public class MainApplication extends Application {
	
	@Override
	public void onCreate() {
		super.onCreate();
		HttpManager.createDefaultHttpManager(null, null, this);
		initImageLoader();
		JPushInterface.init(this);
		JPushInterface.stopPush(this);
//		Set<String> tags = new HashSet<String>();
//		tags.add("20119976");
//		JPushInterface.setTags(this, tags, null);
	}
	
	private void initImageLoader(){
		DisplayImageOptions options = new DisplayImageOptions.Builder()
		.cacheInMemory(true)
		.cacheOnDisk(true)
		.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
		.showImageOnLoading(R.drawable.info_main_image) // 默认图片
		.showImageForEmptyUri(R.drawable.info_main_image) // url爲空會显示该图片，自己放在drawable里面的
		.showImageOnFail(R.drawable.info_main_image)// 加载失败显示的图片
		.build();

		File cacheDir = StorageUtils
				.getOwnCacheDirectory(getApplicationContext(), 
				"renda/cache");
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
				.defaultDisplayImageOptions(options)
				.diskCache(new UnlimitedDiscCache(cacheDir))
				.diskCacheFileNameGenerator(new Md5FileNameGenerator())
				.build();
		ImageLoader.getInstance().init(config); // 初始化
	}

}
